import { ajax } from '@/utils'

import { ExpressTempleteItem, JindouGiftGoodsItem } from './jindouGiftTypes'
import { JindouOrderDetail } from './jindouLifeTyps'

const baseUrl = '/yswy-jdzq-back-service'

export default {
  /** 运费模板列表 */
  getExpressTempleteList(data): Promise<any> {
    return ajax.post(`${baseUrl}/transitTemplate/list`, data)
  },
  /** 新增运费模板*/
  addExpressTemplete(data): Promise<any> {
    return ajax.post(`${baseUrl}/transitTemplate/add`, data)
  },

  /** 编辑运费模板*/
  editExpressTemplete(data): Promise<any> {
    return ajax.put(`${baseUrl}/transitTemplate/edit`, data)
  },

  /** 启用/禁用运费模板*/
  upDownExpressTemplete(id): Promise<any> {
    return ajax.post(`${baseUrl}/transitTemplate/upDown/${id}`)
  },

  /** 选择运费模板列表*/
  getSelectExpressTempleteList(): Promise<ExpressTempleteItem[]> {
    return ajax.get(`${baseUrl}/transitTemplate/simpleList`)
  },

  /** 商品列表列表*/
  getGoodsList(data): Promise<any> {
    return ajax.post(`${baseUrl}/exchangeGoods/list`, data)
  },
  /** 上架/下架运商品*/
  upDownGoods(ids, status): Promise<any> {
    return ajax.put(`${baseUrl}/exchangeGoods/batchUpDown`, { ids, status })
  },
  /** 手动同步*/
  goodsSync(): Promise<any> {
    return ajax.post(`${baseUrl}/exchangeGoods/sync`)
  },
  /** 获取商品详情*/
  getGoodsDetail(id): Promise<JindouGiftGoodsItem> {
    return ajax.get(`${baseUrl}/exchangeGoods/detail/${id}`)
  },
  /** 新增商品*/
  addGoods(data): Promise<any> {
    return ajax.post(`${baseUrl}/exchangeGoods/create`, data)
  },
  /** 编辑商品*/
  editGoods(data): Promise<any> {
    return ajax.put(`${baseUrl}/exchangeGoods/edit`, data)
  },
  /** 禁用启用规格商品*/
  upDownSku(id): Promise<any> {
    return ajax.post(`${baseUrl}/exchangeGoods/disableSpec/${id}`)
  },

  /** 同步Erp商品*/
  syncSkuErpStock(id, warehouse): Promise<any> {
    return ajax.get(
      `${baseUrl}/exchangeGoods/erpStock?id=${id}&warehouse=${warehouse}`
    )
  },
  /** 设置排序*/
  setGoodsSort(id, sort): Promise<any> {
    return ajax.post(`${baseUrl}/exchangeGoods/sort`, { id, sort })
  },
  /** 获取兑好礼优惠卷*/
  getJindouGiftCouponList(): Promise<any> {
    return ajax.get(`${baseUrl}/exchangeGoods/couponList?type=5`)
  },

  /** 订单列表 */
  getOrderList(data): Promise<any> {
    return ajax.post(`${baseUrl}/exchangeGoodsOrder/list`, data)
  },
  /** 订单详情 */
  getOrderDetail(orderNo): Promise<JindouOrderDetail> {
    return ajax.get(`${baseUrl}/exchangeGoodsOrder/detail/${orderNo}`)
  },
  /** 售后 */
  afterSales(orderNo, amount): Promise<any> {
    return ajax.post(
      `${baseUrl}/exchangeGoodsOrder/refund/${orderNo}/${amount}`
    )
  },
  /** 售后订单列表 */
  getRefundList(data): Promise<any> {
    return ajax.post(`${baseUrl}/exchangeGoodsOrder/refundList`, data)
  },
  /** 物流详情 */
  getExpressDetail(orderNo): Promise<any> {
    return ajax.get(`${baseUrl}/exchangeGoodsOrder/transit/${orderNo}`)
  }
}
